package widgets

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
)

// SimpleTextBox 简单文本显示框（直接在canvas上显示纯文本）
type SimpleTextBox struct {
	widget.BaseWidget
	text   string
	scroll *container.Scroll
	label  *widget.Label
}

// NewSimpleTextBox 创建简单文本显示框
func NewSimpleTextBox(minRows int) *SimpleTextBox {
	stb := &SimpleTextBox{
		label: widget.NewLabel(""),
	}

	stb.label.Wrapping = fyne.TextWrapWord
	stb.scroll = container.NewScroll(stb.label)
	stb.scroll.SetMinSize(fyne.NewSize(100, float32(minRows*16)))

	stb.ExtendBaseWidget(stb)
	return stb
}

// SetText 设置文本内容
func (stb *SimpleTextBox) SetText(text string) {
	stb.text = text
	stb.label.SetText(text)
}

// Text 获取文本内容
func (stb *SimpleTextBox) Text() string {
	return stb.text
}

// CreateRenderer 创建渲染器
func (stb *SimpleTextBox) CreateRenderer() fyne.WidgetRenderer {
	return widget.NewSimpleRenderer(stb.scroll)
}

// MinSize 返回最小尺寸
func (stb *SimpleTextBox) MinSize() fyne.Size {
	return stb.scroll.MinSize()
}

// Resize 调整大小
func (stb *SimpleTextBox) Resize(size fyne.Size) {
	stb.BaseWidget.Resize(size)
	stb.scroll.Resize(size)
}
